package com.cloudkinto.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cloudkinto.entity.StockRecordDo;
import com.cloudkinto.extentity.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 张永远
 * @since 2020-06-10
 */
@Mapper
public interface StockRecordDao extends BaseMapper<StockRecordDo> {

    List<StockRecordPageDto> listPage(IPage<StockRecordPageDto> page, @Param("map") Map<String, String> map);

    List<StockRecordPageDto> listPage(@Param("map") Map<String, String> map);

    List<StockRecordDto> getStockRecord(@Param("map") Map<String, String> map);


    /**
     * 一件代发未发货数量
     *
     * @param productId
     * @param shopId
     * @param storageId
     * @return
     */
    int getOrderOutCount(long productId, long shopId, long storageId);

    /**
     * 在途数量
     *
     * @param productId
     * @param shopId
     * @param storageId
     * @return
     */
    int getOrderInCount(long productId, long shopId, long storageId);

    double getRakutenRate( String shopId, String companyId, String startDate, String endDate);
    double getRakutenRateBySku(long productId, long shopId, long storageId, long companyId, String startDate, String endDate);

    double getAmazonRate( String shopId,  String companyId, String startDate, String endDate);
    double getAmazonRateBySku(long productId, long shopId, long storageId, long companyId, String startDate, String endDate);
    int updateStockById(Long id, int goodQuantity);

    /**
     * 待转运FBA数量
     *
     * @param productId
     * @param shopId
     * @param storageId
     * @return
     */
    int getOrderOutTurn2FbaCount(long productId, long shopId, long storageId);

    List<StockTurnoverRateDto> turnoverRateList(IPage<StockTurnoverRateDto> page, @Param("map") Map<String, String> map);

    Double turnoverRateTotal(@Param("map") Map<String, String> map);

    /****************库存快照模块*******************/

    List<StockSnapshotPageDto> getStockSnapshotList(IPage<StockSnapshotPageDto> page, @Param("map") Map<String, String> map);

    List<StockSnapshotPageDto> getStockSnapshotList(@Param("map") Map<String, String> map);

    List<StockAgeDto> getStockAgeAnalysis(List<Long> storageIdList, @Param("companyId") Long companyId);

    List<StockAgeSkuDTO> getStockAgeSkuList(List<Long> storageIdList, List<Long> productIdList,@Param("companyId")  Long companyId);


    List<ProductStockDto> getProductStockDetail(@Param("map") Map<String, String> map);

    IPage<StockRecordNewDto> getStockListGroupCompany(IPage<StockRecordNewDto> page, @Param("map") Map<String, String> map);
}
